// pages/search/search.js
var app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({
      type: options.type
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  // 获取输入框的值
  getInput: function (e) {
    this.setData({
      inputVal: e.detail.value
    })
  },
  //开始搜索
  search:function(){
    var that=this;
    if (that.data.type == 4) {
      var data = {
        paraUrl: "group/page?brand=false&page=" + that.data.page + "&size=5&keywords=" + that.data.inputVal,
        paraData: ''
      }
      app.getRequest(data, function (res) {
        if (res.data.result == 200) {
          var groupList = res.data.body.content
          that.setData({
            groupList: groupList,
            allPage: res.data.body.totalPages
          })
        } else {
        }
      })
    } else if (that.data.type == 1){
      var data = {
        paraUrl: "task/page?activity=true&keywords=" + that.data.inputVal+"&regionId=&type=&statusCode&page=" + that.data.page + "&size=6",
        paraData: ''
      }
      app.getRequest(data, function (res) {
        if (res.data.result == 200) {
          var array_huodong = res.data.body.content
          that.setData({
            array_huodong: array_huodong,
            allPage: res.data.body.totalPages
          })
        } else {
        }
      })
    } else if (that.data.type == 5){
      var data2 = {
        paraUrl: "group/page?brand=true&page=" + that.data.page + "&size=5&keywords=" + that.data.inputVal,
        paraData: ''
      }
      app.getRequest(data2, function (res) {
        if (res.data.result == 200) {
          var groupList = res.data.body.content
          that.setData({
            groupList: groupList,
            allPage: res.data.body.totalPages
          })
        } else {
        }
      })
    }
  },
  // 点击查看群组详情
  clickDetail: function (e) {
    wx.setStorageSync('qundetail', e.currentTarget.id);
    wx.navigateTo({
      url: '../GroupDetail/GroupDetail'
    })
  },
  toActivityDetail: function (e) {
    wx.setStorageSync("taskId", e.currentTarget.id)
    wx.navigateTo({
      url: '/pages/ActivityDetail/ActivityDetail'
    })
  }
})